package com.dz.risk.aspect;

import com.dz.risk.custom.dynamic.FormulaCalculation;
import com.dz.risk.pojo.model.FormulaExtModel;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 报表数据值切面处理类
 *
 * @author Doke
 * @date 2021/8/10 16:20
 */
@Aspect
@Component
public class ReportFormsDataValueAop {

    private final FormulaCalculation formulaCalculation;

    @Autowired
    public ReportFormsDataValueAop(FormulaCalculation formulaCalculation) {
        this.formulaCalculation = formulaCalculation;
    }

    /**
     * 验证设置公式时,所引用的参数是否能够被引用
     *
     * @param point
     * @return
     * @throws Throwable
     */
    @Around("execution(* com.dz.risk.service.impl.ReportFormsDataValueServiceImpl.updateFormulaById(..))")
    public Object checkUpdateFormulaById(ProceedingJoinPoint point) throws Throwable {
        Object[] args = point.getArgs();
        FormulaExtModel formulaExtModel = (FormulaExtModel) args[0];

        //判断是否需要验证公式
        if (formulaExtModel.getWhetherToVerifyTheFormula()) {
            //计算公式,验证公式是否能够计算
            formulaCalculation.checkCalculation(formulaExtModel.getCellFormula().getFormulaDetails(), formulaExtModel.getCellFormula().getParseFormula());
        }

        return point.proceed();
    }


}
